/**
 * HelloJbpmAction.java
 * com.capinfo.jbpmtest.admin.actions
 *
 * Function： TODO 
 *
 *   ver     date      		author
 * ──────────────────────────────────
 *   		 2011-4-27 		spring
 *
 * Copyright (c) 2011, TNT All Rights Reserved.
*/

package com.capinfo.jbpmtest.admin.actions;

import java.util.List;

import org.jbpm.api.ProcessDefinition;
import org.jbpm.api.ProcessEngine;
import org.jbpm.api.RepositoryService;

import com.opensymphony.xwork2.ActionSupport;

/**
 * ClassName:HelloJbpmAction
 * Reason:	 测试JBPM 的action
 *
 * @author   spring
 * @version  
 * @since    Ver 1.1
 * @Date	 2011-4-27		下午02:38:12
 *
 * @see 	 
 */
public class HelloJbpmAction extends ActionSupport {

	private ProcessEngine engine;
	private List<ProcessDefinition> process;
	private String developementId;

	public String list() {
		//获取流程服务  
		RepositoryService service = engine.getRepositoryService();
		//----查看流程定义  
		//发布流程定义信息，查看已发布流程定义列表  
		process = service.createProcessDefinitionQuery().list();//执行搜索  
		return "list";
	}

	public String add() {
		//获取流程服务  
		RepositoryService service = engine.getRepositoryService();
		//把流程定义发布到流程引擎中  
		String developementId = service.createDeployment().addResourceFromClasspath("hello.jpdl.xml").deploy();
		return list();
	}

	public String del() {
		//获取流程服务  
		RepositoryService service = engine.getRepositoryService();
		//----删除流程定义，这里用级联删除会比较好  
		service.deleteDeploymentCascade(developementId);
		return list();
	}

	public ProcessEngine getEngine() {
		return engine;
	}

	public void setEngine(ProcessEngine engine) {
		this.engine = engine;
	}

	public List<ProcessDefinition> getProcess() {
		return process;
	}

	public void setProcess(List<ProcessDefinition> process) {
		this.process = process;
	}

}
